package cn.kgc.web.service.impl;

import cn.kgc.base.entity.Clazz;
import cn.kgc.base.entity.Group;
import cn.kgc.base.utils.ResponseResult;
import cn.kgc.web.client.ClazzClient;
import cn.kgc.web.mapper.GroupMapper;
import cn.kgc.web.service.GroupService;
import cn.kgc.web.vo.GroupVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author mengshun
* @description 针对表【t_group】的数据库操作Service实现
* @createDate 2024-01-11 09:44:33
*/
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group>implements GroupService{

    @Resource
    private ClazzClient clazzClient;

    @Override
    public ResponseResult groupList() {

        //  1.查询group表
        List<Group> groups = baseMapper.selectList(null);

        // 2.根据小组的班级id  查询班级服务 获取班级的具体信息
        List<GroupVO> collect = groups.stream().map(group -> {
            GroupVO groupVO = new GroupVO();
            BeanUtils.copyProperties(group,groupVO);

            int clazzid = Integer.parseInt(group.getClazzid()) ;
            //  调用班级服务  查询班级具体信息
            Clazz clazz = clazzClient.getById(clazzid);
            groupVO.setClazz(clazz);
            return groupVO;
        }).collect(Collectors.toList());

        return ResponseResult.success().data(collect);
    }
}




